package leetcode;

import java.util.ArrayList;
import java.util.List;

public class a222完全二叉树的节点个数 {
    public int countNodes(TreeNode root) {
        List<Integer> res= new ArrayList<Integer>();
        preorder(root,res);
        return res.size();



    }
    public void preorder(TreeNode root, List<Integer> res){
        if(root==null){
            return;
        }
        res.add(root.val);
        preorder(root.left,res);
        preorder(root.right,res);

    }


//    递归
    public int countNodes1(TreeNode root) {
        if(root==null){
            return 0;
        }
        int left=countNodes1(root.left);
        int right=countNodes1(root.right);

        return left+right+1;



    }



}
